{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
    <div class="think-box-shadow">
        <form class="layui-form layui-form-pane form-search" action="{:request()->url()}" onsubmit="return false" method="get" autocomplete="off">

            <div class="layui-form-item layui-inline">
                <label class="layui-form-label"></label>
                <div class="layui-input-inline">
                    <input name="pName" value="" placeholder="供应商"   class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-inline">
                <label class="layui-form-label"></label>
                <div class="layui-input-inline">
                    <input name="orderNum" value="" placeholder="关联采购合同"   class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-inline">
                <button class="layui-btn layui-btn-primary" lay-submit="" lay-filter="webform"><i class="layui-icon">&#xe615;</i> 搜 索</button>
            </div>
        </form>
        <table class="layui-table margin-top-10" lay-filter="mxTable" lay-skin="line" id="mxTable">
        </table>
        <script type="text/html" id="toolbarDemo">
            <button class="layui-btn layui-btn-sm layui-btn-normal " lay-event="subt" type="button">确认</button>
        </script>
    </div>
{/block}
{block name="script"}
<!-- /主体 -->
<script>
    const moduleInit = ['tool','table'];
    function gouguInit() {
        var form =layui.form;

        var treeTable = layui.table;
        // $.extend(treeTable, {config: {checkName: 'checked'}});
        var tableIns = treeTable.render({
            elem: '#mxTable'
            , url: "{:url('api/getSaleMxLockData')}?mdId={$sdInfo.mdId}&detailId={$sdInfo.id}"
            , method: 'post'
            , toolbar: '#toolbarDemo',
            defaultToolbar: []
            , cellMinWidth: 80
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'id', width: 80, title: 'ID号', align: 'center'}
                // , {field: 'checkTime', title: '入库时间'}
                // , {field: 'wName', title: '仓库'}
                , {field: 'pName', title: '供应商'}
                , {field: 'saleContractOrder', title: '关联采购合同'}
                , {field: 'bjPrice', title: '单价'}
                , {field: 'dayLong', title: '在库天数 '}
                , {field: 'num', title: '库存数量'}
                , {field: 'lockedNum', title: '已锁定数量'}
                , {field: 'canUse', title: '可用数量'}
                , {field: 'sodRemark', title: '备注'}
                , {field: 'thisLock', title: '本次锁定数量',edit:"number"}
            ]]
            ,parseData:function (data) {
                let tableData=[];
                data.data.forEach(function (item) {
                    if (item.id==item.checkId){
                        item.LAY_CHECKED=true;
                    }else {
                        item.LAY_CHECKED=false;
                    }

                    tableData.push(item)
                })
                data.data=tableData;
                return data;
            }
            , page: true
        });
        form.on('submit(webform)', function (data) {
            tableIns.reload({
                where: data.field,
                page: {
                    curr: 1
                }
            });
            return false;
        });
        treeTable.on('toolbar(mxTable)', function (obj) {
            var checkStatus = treeTable.checkStatus(obj.config.id);
            console.log(checkStatus)
            switch (obj.event) {
                case 'add':
                    break;
                case 'subt':
                    var data = checkStatus.data;
                    var param = []
                    let islert=0;
                        data.forEach(function (value, index) {
                            if (parseFloat(value.canUse)<parseFloat(value.thisLock)){
                                islert=1;
                            }
                            if (value.thisLock!=''&&parseFloat(value.thisLock)>0){
                                param.push(value)
                            }
                        })
                    if (islert!=0){
                        layer.msg('可用数量小于锁定数量');
                        return;
                    }
                        httpRequest("{:url('lock')}?sdId={$sdInfo.id}",{data:param},function (res) {
                            if (res.code==0){
                                setTimeout(function () {
                                    parent.parent.location.reload();
                                },1000)

                            }
                        })

                    break;
                case 'import':

                    break;

            }
            ;
        })

    }

    function saveMx(data) {
        parent.saveAddMx(data)

    }
</script>
<!-- 脚本 -->
{/block}


